package com.liziba.mq.topic.consumer.rabbit;

import org.springframework.amqp.rabbit.annotation.RabbitHandler;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;

import java.util.Map;

/**
 * @auther LiZiBa
 * @date 2021/1/31 23:50
 * @description: 不做手动确认处理
 **/
@Component
public class TopicConsumer {

    /**
     * 查看消费情况可以发现logger.info有两条消息
     * TopicConsumer1{createTime=2021-01-31 23:47:04, messageId=85667651-7dd9-4cfa-b2d2-aac74cc69ade, messageData=test message, hello!}
     * TopicConsumer2{createTime=2021-01-31 23:46:42, messageId=7719582a-fc6c-4450-947a-4e551232a2f3, messageData=test message, hello!}
     * TopicConsumer2{createTime=2021-01-31 23:47:04, messageId=85667651-7dd9-4cfa-b2d2-aac74cc69ade, messageData=test message, hello!}
     */


    @RabbitListener(queues = "logger.error")
    @RabbitHandler
    public void handleErrorMessage(Map message) {
        System.out.println("TopicConsumer1" + message.toString());
    }


    @RabbitListener(queues = "logger.info")
    @RabbitHandler
    public void handleInfoAndErrorMessage(Map message) {
        System.out.println("TopicConsumer2" + message.toString());
    }
}
